<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input type="file" id="ff">
    <input type="button" value="AJAX请求" id="btn">
</body>
<script>
    var oBtn = document.getElementById('btn')
    var ff=document.getElementById('ff');
    
    btn.onclick = function () {
        var xhr = new XMLHttpRequest();
        // xhr.open('get','1.php?a=12&b=6',true);//第三个参数代表同步还是异步  true表示异步
        var formData = new FormData();
        formData.set('f1', ff)

        xhr.upload.onload=function(){
            console.log('上传完成');
        }
        xhr.upload.onprogress=function(ev){
            console.log(ev.loaded,ev.total)
        }


        xhr.open('get', '1.php', true);
        // xhr.send();
        xhr.send(formData);

        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304) {
                    alert(xhr.responseText);
                } else {
                    alert('错了');
                }
            }
        }

    }






</script>

</html>